// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   IndicadoresDeCoyunturaAction.java

package org.fiel.struts.actions;

import java.util.*;
import javax.servlet.ServletRequest;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.fiel.commons.jdbc.Constraint;
import org.fiel.commons.jdbc.Finder;
import org.fiel.persistence.AnioDescripcionPersistor;
import org.fiel.persistence.InformacionPersistor;

// Referenced classes of package org.fiel.struts.actions:
//            ListaSubtiposAction, FielAction

public class IndicadoresDeCoyunturaAction extends ListaSubtiposAction
{

    public IndicadoresDeCoyunturaAction()
    {
    }

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws Exception
    {
        String forward = request.getParameter("mapping");
        Integer tipo = new Integer(13);
        String rol = obtenerRol(request);
        List aniosList = null;
        List subtipohistoricoList = null;
        List seccionesList = null;
        if(rol.indexOf("1") != -1)
        {
            aniosList = obtenerListaAnios();
            request.getSession().setAttribute("listaanios", aniosList);
        }
        if(rol.indexOf("3") != -1)
        {
            subtipohistoricoList = ObtenerSubtipos(new Integer(4));
            request.getSession().setAttribute("historicos", subtipohistoricoList);
        }
        List subtipoList = ObtenerSubtipos(tipo);
        List cuadrosList = ObtenerInformacionSubtipos(subtipoList, null);
        List libres = getInformacionLibres(rol);
        if(rol.indexOf("1") == -1 && rol.indexOf("3") == -1)
            seccionesList = obtenerListaSecciones();
        request.getSession().setAttribute("secciones", seccionesList);
        request.getSession().setAttribute("libres", libres);
        request.getSession().setAttribute("cuadros", cuadrosList);
        return mapping.findForward(forward);
    }

    private List getInformacionLibres(String rol)
    {
        if(rol.indexOf("1") == -1)
        {
            String fHasta = null;
            GregorianCalendar fecha = null;
            fecha = (GregorianCalendar)Calendar.getInstance();
            fecha.add(2, -12);
            String fDesde = Integer.toString(fecha.get(1)) + "-" + Integer.toString(fecha.get(2)) + "-" + Integer.toString(fecha.get(5));
            fecha.add(2, 6);
            fHasta = Integer.toString(fecha.get(1)) + "-" + Integer.toString(fecha.get(2)) + "-" + Integer.toString(fecha.get(5));
            Finder persistor = new InformacionPersistor();
            List constraints = new ArrayList();
            constraints.add(new Constraint("identipo", "=", new Integer(3)));
            constraints.add(new Constraint("fechae", ">=", fDesde));
            constraints.add(new Constraint("fechae", "<=", fHasta));
            return persistor.FindAll(constraints);
        } else
        {
            String fDesde = null;
            GregorianCalendar fecha = null;
            fecha = (GregorianCalendar)Calendar.getInstance();
            fecha.add(2, -6);
            fDesde = Integer.toString(fecha.get(1)) + "-" + Integer.toString(fecha.get(2)) + "-" + Integer.toString(fecha.get(5));
            Finder persistor = new InformacionPersistor();
            List constraints = new ArrayList();
            constraints.add(new Constraint("identipo", "=", new Integer(3)));
            constraints.add(new Constraint("nivel", "=", new Integer(1)));
            constraints.add(new Constraint("fechae", ">=", fDesde));
            return persistor.FindAll(constraints);
        }
    }

    private List obtenerListaAnios()
    {
        List constraints = new ArrayList();
        constraints.add(new Constraint("identipo", "=", new Integer(3)));
        Finder persistor = new AnioDescripcionPersistor();
        return persistor.FindAll(constraints);
    }

    private List obtenerListaSecciones()
    {
        List constraints = new ArrayList();
        constraints.add(new Constraint("identipo", "=", new Integer(3)));
        constraints.add(new Constraint("nivel", "=", new Integer(0)));
        Finder persistor = new InformacionPersistor();
        return persistor.FindAll(constraints);
    }
}
